#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>

char *ps = NULL;
char *str;
int n;
FILE *f;

void *thread(void *arg)
{
    pthread_detach(pthread_self());
    ps = fgets(str, n, f);
    pthread_kill(*(pthread_t *)arg, SIGCHLD);
    return NULL;
}

void func(int sig)
{
    return;
}

char * tfgets(char *s, int size, FILE *stream)
{
    pthread_t tid, self;
    
    str = s;
    n = size;
    f = stream;

    self = pthread_self();
    pthread_create(&tid, NULL, thread, (void *)&self);

    signal(SIGCHLD, func);

    sleep(5);

    return ps;
}
